#!/usr/bin/python

import os, sys, webbrowser

#First set up the web server that is going to listen port 8000, fork it

def getHostIP():
	import socket
	import fcntl
	import struct
   	ifname='eth0'
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    	return socket.inet_ntoa(fcntl.ioctl(
        	s.fileno(),
        	0x8915,  # SIOCGIFADDR
        	struct.pack('256s', ifname[:15])
    	)[20:24])
	
def main(): 
	os.chdir('./webserverScripts')
	L = ['python', './server.py']
	pid = os.spawnvpe(os.P_NOWAIT, 'python', L, os.environ)

	#Write the pid of the server in a file
	f = open('./../pids','w')
	f.write(str(pid)+' ' )
	f.close()

	print "You can know have access to the UI with your browser at the address"+getHostIP()+":8000 . "
 	

if __name__ == '__main__':
	main()	
	
